<?php

include_once 'db.php';

class Bill_detail extends Db {

    public $table_name = "bill_detailed";

    public function __construct() {
        parent::__construct();
    }

    public function select($params,$id) {
        /**
         * TODO: Write your code here
         */
        $query = "SELECT * FROM {$this->table_name} WHERE idbill = {$id}";//SQL query
        if(!empty($params['offset']))
        {
            $offset = ($params['offset'] - 1) * PER_PAGE;
            $query .= ' LIMIT ' .$offset. ', ' .PER_PAGE;
        }
        $data = parent::select($query);
        return $data;
    }
    public function selectid($id) {
        /**
         * TODO: Write your code here
         */
        $query = "SELECT * FROM {$this->table_name} WHERE id = {$id}";//SQL query
        $data = parent::select($query);
        return $data;
    }
    public function count($id)
    {
        $query = "SELECT COUNT(*) AS COUNT FROM {$this->table_name} WHERE idbill = {$id}";
        $data = parent::select($query);
        return (int) $data[0]['COUNT'];
    }
    public function insert($name,$quantity,$cost,$id) {
        /**
         * TODO: Write your code here
         */
        $query = "INSERT INTO bill_detailed (id,nameproduct,quantity,totalcost,idbill) VALUES('', '".$name."', '".$quantity."', '".$cost."', '".$id."')";//SQL query
        $data = parent::insert($query);
        return $data;
    }
    public function update($quantity, $totalcost, $id) {
        /**
         * TODO: Write your code here
         */
        $query = 'UPDATE '.$this->table_name.' SET quantity = '.$quantity.',totalcost = '.$totalcost.' WHERE id = '.$id;//SQL query
        $data = parent::update($query);
        return $data;
    }
    public function delete($id) {
        /**
         * TODO: Write your code here
         */
        $query = 'DELETE FROM '.$this->table_name.' WHERE id = '.$id;//SQL query
        $data = parent::delete($query);
        return $data;
    }
 

}
